/*
 * Jenny Ruppen 09-730-391
 * Sebastien Goldberg 08-914-855
 * Henry Raymond 08-928-061
 * Stefan Mussato 09-752-270
 */
 
package ch.uzh.ifi.sopra.gruppe9.game;

import com.jme3.scene.Node;


/**
 * Draws a slot box in the GUI.
 */
public class GuiSlot extends Node {
	
	
	/**
	 * Offset of the coordinate system of this element.
	 */
	private GUI.Offset offset;
	
	
	/**
	 * Position of the element in the x axis. (Assuming the window has a width of 1024 pixel.)
	 */
	private int positionX;
	
	
	/**
	 * Position of the element in the y axis. (Assuming the window has a height of 768 pixel.)
	 */
	private int positionY;
	
	
	/**
	 * Width of the element. (Assuming the window has a width of 1024 pixel.)
	 */
	private int width;
	
	
	/**
	 * Height of the element. (Assuming the window has a height of 768 pixel.)
	 */
	private int height;
	
	
	/**
	 * Z-Index of the element. An element with a higher index will cover an element with a lower one.
	 */
	private int zIndex;
	
	
	/**
	 * Node of the geometry of the slot.
	 */
	private Node slot;
	
	
	/**
	 * Elements of the slot.
	 */
	private GuiQuad cornerTopLeft;
	private GuiQuad cornerTopRight;
	private GuiQuad cornerBottomLeft;
	private GuiQuad cornerBottomRight;
	private GuiQuad lineTop;
	private GuiQuad lineBottom;
	private GuiQuad lineLeft;
	private GuiQuad lineRight;
	private GuiQuad background;
	
	
	/**
	 * Constructor
	 */
	public GuiSlot(GUI.Offset offset, int positionX, int positionY, int width, int height, int zIndex) {
		this.offset = offset;
		this.positionX = positionX;
		this.positionY = positionY;
		this.width = width;
		this.height = height;
		this.zIndex = zIndex;
		
		slot = new Node();
		
		cornerTopLeft = new GuiQuad();
		cornerTopLeft.setAbsolutePositionSize(-10, -10, 20, 20, 0);
		cornerTopLeft.setMaterial(MaterialManager.getSlot(), 0.0f, 0.0f, 0.25f, 0.25f);
		slot.attachChild(cornerTopLeft.create());
		
		cornerTopRight = new GuiQuad();
		cornerTopRight.setAbsolutePositionSize(width - 10, -10, 20, 20, 0);
		cornerTopRight.setMaterial(MaterialManager.getSlot(), 0.75f, 0.0f, 0.25f, 0.25f);
		slot.attachChild(cornerTopRight.create());
		
		cornerBottomLeft = new GuiQuad();
		cornerBottomLeft.setAbsolutePositionSize(-10, height - 10, 20, 20, 0);
		cornerBottomLeft.setMaterial(MaterialManager.getSlot(), 0.0f, 0.75f, 0.25f, 0.25f);
		slot.attachChild(cornerBottomLeft.create());
		
		cornerBottomRight = new GuiQuad();
		cornerBottomRight.setAbsolutePositionSize(width - 10, height - 10, 20, 20, 0);
		cornerBottomRight.setMaterial(MaterialManager.getSlot(), 0.75f, 0.75f, 0.25f, 0.25f);
		slot.attachChild(cornerBottomRight.create());
		
		lineTop = new GuiQuad();
		lineTop.setAbsolutePositionSize(10, -10, width - 20, 20, 0);
		lineTop.setMaterial(MaterialManager.getSlot(), 0.25f, 0.0f, 0.25f, 0.25f);
		slot.attachChild(lineTop.create());
		
		lineBottom = new GuiQuad();
		lineBottom.setAbsolutePositionSize(10, height - 10, width - 20, 20, 0);
		lineBottom.setMaterial(MaterialManager.getSlot(), 0.25f, 0.75f, 0.25f, 0.25f);
		slot.attachChild(lineBottom.create());
		
		lineLeft = new GuiQuad();
		lineLeft.setAbsolutePositionSize(-10, 10, 20, height - 20, 0);
		lineLeft.setMaterial(MaterialManager.getSlot(), 0.0f, 0.25f, 0.25f, 0.25f);
		slot.attachChild(lineLeft.create());
		
		lineRight = new GuiQuad();
		lineRight.setAbsolutePositionSize(width - 10, 10, 20, height - 20, 0);
		lineRight.setMaterial(MaterialManager.getSlot(), 0.75f, 0.25f, 0.25f, 0.25f);
		slot.attachChild(lineRight.create());
		
		background = new GuiQuad();
		background.setAbsolutePositionSize(10, 10, width - 20, height - 20, -0.5f);
		background.setMaterial(MaterialManager.getSlot(), 0.25f, 0.25f, 0.25f, 0.25f);
		slot.attachChild(background.create());
		
		slot.setLocalTranslation(GUI.calculateX(offset, positionX), GUI.calculateY(offset, positionY), (float)zIndex);
		
        this.attachChild(slot);

	}


	public GUI.Offset getOffset() {
		return offset;
	}


	public int getPositionX() {
		return positionX;
	}


	public int getPositionY() {
		return positionY;
	}


	public int getWidth() {
		return width;
	}


	public int getHeight() {
		return height;
	}


	public int getzIndex() {
		return zIndex;
	}
}
